package org.budo.dubbo.protocol.async;

import org.budo.dubbo.protocol.async.util.ExporterUtil;

import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.protocol.AbstractExporter;

/**
 * 暴露一个异步服务，启动一个收消息的线程
 * 
 * @author lmw
 */
public class BudoAsyncDubboExporter<T> extends AbstractExporter<T> {
    private BudoAsyncDubboProtocol _protocol;

    private PopThread _popThread;

    public BudoAsyncDubboExporter(Invoker<T> invoker, BudoAsyncDubboProtocol protocol) {
        super(invoker);

        this._protocol = protocol;

        // exportMe
        this._popThread = new PopThread(this) //
                .startThread(); // 启线程
    }

    public void unexport() {
        super.unexport();

        // 停线程
        this._popThread.stopThread();

        String exporterKey = ExporterUtil.exporterKey(this.getInvoker());
        this._protocol.getExporterMap().remove(exporterKey);
    }
}